Array.prototype.quickSort = function() {
  /**
   * 快速排序
   * @param {any} x 数组首位元素
   * @param {Array} xs 待排序数组
   */
  const qsort = (x, ...xs) => {
    const sortAgain = f => arr => {
      const res = arr.filter(f);
      return res.length > 0 ? qsort(...res) : [];
    };

    return xs.length === 0
      ? [x]
      : [...sortAgain(v => v < x)(xs), x, ...sortAgain(v => v > x)(xs)];
  };

  return qsort(...this);
};

console.log([5, 4, 3, 2, 1].quickSort()); // Array(5) [1, 2, 3, 4, 5]
